﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using SN.Data;
using System.Data;
namespace Agro.Web.Areas.FileManage.Controllers
{
    public class UploadController : Controller
    {
        //
        // GET: /FileManage/Upload/
        [HttpPost]
        public ActionResult Index(HttpPostedFileBase FileData, string GUID)
        {
            string fileName = string.Empty;
            try
            {
                fileName = Path.GetFileName(FileData.FileName);

                string fileExtension = System.IO.Path.GetExtension(fileName);
                string saveDir = Server.MapPath("~/Files/");
                Random objRand = new Random();
                System.DateTime date = DateTime.Now;
                //生成随机文件名
                string saveName = date.Year.ToString() + date.Month.ToString() + date.Day.ToString() + date.Hour.ToString() + date.Minute.ToString()

                    + date.Second.ToString() + Convert.ToString(objRand.Next(99) * 97 + 100);
                saveName = saveName + fileExtension;
                if (!System.IO.Directory.Exists(saveDir))
                {
                    System.IO.Directory.CreateDirectory(saveDir);
                }
                FileData.SaveAs(saveDir + "/" + saveName);
                string returnstr = "[{'filename':'" + fileName + "','savefilename':'" + saveName + "','fileExtension':'" + fileExtension.Replace(".", "") + "'}]";
                return Content(returnstr);
            }
            catch (Exception ex)
            {
                fileName = "";
            }

            return Content(fileName);

        }
        public ActionResult test()
        {
            DataTable dt=SN.Data.DbSessionFactory.GetDbSession().FromSql("select * from t_menu").ToDataTable();
            int c = dt.Rows.Count;
            return Content("q");
        }


     


    }
}
